package com.test.base;


import java.lang.reflect.ParameterizedType;


import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
/**
 * 定义了一个基础的Action，采用了模型驱动方式封装参数
 * @author SingleHe 2015-10-8
 *
 * @param <T>
 */
public class BaseAction<T> extends ActionSupport implements ModelDriven<T> {
	//===========================声明Service==============================
	//使用了注解方式从容器中获得对应的service
//	@Resource
//	protected JuesInfoService juesInfoService;
//	@Resource
//	protected UserInfoService userInfoService;
	//=========================对ModelDriven的支持=========================
	private static final long serialVersionUID = 1L;
	protected T model;
	@SuppressWarnings("unchecked")
	public BaseAction(){
		System.out.println("----------> BaseAction.BaseAction()");
		try{
			//通过反射获得T的真实类型
			ParameterizedType pt = (ParameterizedType)this.getClass().getGenericSuperclass();
			Class<T> clazz = (Class<T>)pt.getActualTypeArguments()[0];
			//通过反射创建Model的实例
			model = clazz.newInstance();
		}catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	public T getModel() {
		// TODO Auto-generated method stub
		return model;
	}

}
